import { defineStore } from "pinia";
const useCounter = defineStore("counter", {
    state: () =>
    {
        //这里要进行返回，才能被获取到。
        return {
            count: 99,
            users:[{name:"cq",id:1},{name:"kobe",id:40}]
       }
    },
    getters:
    {
        //使用state里面的数据
        doubleCounter: (state) => {
            return state.count * 2;
        },
        //使用getters里面的属性
        fourCounter: (state) =>
        {
            return state.doubleCounter * 2;    
        },
        //调用一个传入参数的函数
        findById:(state) =>(id)=>
        {
           
            return state.users.find(user => user.id===id);
        }

    },
    actions:
    {
        sum(a, b)
        {
            return a + b;
        }
    }
})

export default useCounter;